<?php
namespace UserApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ComplaintsApiController extends AbstractRestfulController
{
    public function getList()
    {
    }
    public function get($user_id)
    {	
		header('Access-Control-Allow-Origin: *');
		$allComplaints=array();
		$complaintsTable=$this->getServiceLocator()->get('Models\Model\ComplaintsFactory');	
		$explodeId=explode('-',$user_id);
		$user_id=$explodeId[0];
		$getComplaints = $complaintsTable->getComplaints($user_id)->toArray();
		if(count($getComplaints)!=0){
			return new JsonModel(array(
				'output'		=> 'success',
				'value'        	=> 1,
				'result'	    => $getComplaints,
			));
		}else{
			return new JsonModel(array(
				'output'	=> 'fail',
				'value'        =>0,
			));
		}
    }
    public function create($complaint)
    {
		header('Access-Control-Allow-Origin: *');
		$userMedicineOrderTable=$this->getServiceLocator()->get('Models\Model\UserMedicineOrderFactory');
		$checkOrder = $userMedicineOrderTable->checkOrder($complaint['tracking_id'],$complaint['user_id']);
		if($checkOrder!=0){
			$complaintsTable=$this->getServiceLocator()->get('Models\Model\ComplaintsFactory');
			$notificationTable=$this->getServiceLocator()->get('Models\Model\NotificationsFactory');
			$orderDeliveryTable=$this->getServiceLocator()->get('Models\Model\OrderDeliveryDetailsFactory');
			$postComplaint = $complaintsTable->postComplaint($complaint);
			$getComplaintshopId=$orderDeliveryTable->getComplaintshopId($complaint['tracking_id'])->toArray();
			if(count($getComplaintshopId)!=0){
				$sendNotification=$notificationTable->sendShopComplaint($complaint,'2','0',$getComplaintshopId[0]['shop_id'],'0','3');
			}else{
				$sendNotification=$notificationTable->sendShopComplaint($complaint,'2','0','0','0','3');
			}
			$sendNotification=$notificationTable->sendAdminComplaint($complaint,'2','0','0','0','1');
			if($postComplaint!=0){
				return new JsonModel(array(
					'output'		=> 'success',
					'complaint_id'	=>	$postComplaint,
					'value'	=> 1,
				));
			}
		
		}else{
				return new JsonModel(array(
					'output'	=> 'fail',
					'value'	=> 0,
				));
			}
    }
    public function update($id,$data)
    {
			
    }
    public function delete($id)
    {
       
    }
}